package com.lktx.sso.admin.controller;

import cn.hserver.core.ioc.annotation.Autowired;
import cn.hserver.plugin.web.annotation.Controller;
import cn.hserver.plugin.web.annotation.GET;
import cn.hserver.plugin.web.annotation.POST;
import cn.hserver.plugin.web.annotation.PUT;
import com.lktx.sso.admin.entity.SsoAppGroup;
import com.lktx.sso.admin.service.SsoAppGroupService;
import com.mybatisflex.core.paginate.Page;
import lombok.extern.slf4j.Slf4j;
import com.lktx.sso.system.common.MyResult;

import java.util.List;
import java.util.Optional;

/**
 * app分组 接口
 */
@Slf4j
@Controller("/ssoAppGroup")
public class SsoAppGroupController {

    @Autowired
    private SsoAppGroupService service;

    /**
     * 分页查询列表
     *
     * @param index  当前页|1
     * @param size   页大小|10
     * @param entity 查询实体
     * @return 所有数据
     */
    @POST("/page/{index}/{size}")
    public MyResult selectAll(SsoAppGroup entity, Long index, Long size) {
        Page<SsoAppGroup> page = new Page<>(index, size);
        return MyResult.of(service.page(page, Optional.ofNullable(entity).orElse(new SsoAppGroup())));
    }


    /**
     * 不分页查询列表
     *
     * @param entity 实体对象
     * @return 查询结果
     */
    @POST("/list")
    public MyResult list(SsoAppGroup entity) {
        return MyResult.of(service.list(Optional.ofNullable(entity).orElse(new SsoAppGroup())));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GET("/get/{id}")
    public MyResult getById(Integer id) {
        return MyResult.of(service.getById(id));
    }

    /**
     * 批量删除数据
     *
     * @param ids 主键集合
     * @return 操作结果
     */
    @POST("/delete")
    public MyResult deleteByIds(List<Integer> ids) {
        service.deleteByIds(ids);
        return MyResult.success();
    }

    /**
     * 新增单条数据
     *
     * @param entity 实体对象
     * @return 新增结果
     */
    @POST
    public MyResult save(SsoAppGroup entity) {
        service.save(entity);
        return MyResult.success();
    }

    /**
     * 修改单条数据
     *
     * @param entity 实体对象
     * @return 修改结果
     */
    @PUT
    public MyResult update(SsoAppGroup entity) {
        service.update(entity);
        return MyResult.success();
    }

}
